﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;

namespace Blip.UI.Controls
{
    /// <summary>
    /// Okno dialogowe.
    /// </summary>
    public partial class Dialog : SurfaceUserControl
    {
        /// <summary>
        /// Zdarzenie generowane po zaakceptowaniu pytania.
        /// </summary>
        public event EventHandler Yes;
        
        /// <summary>
        /// Zdarzenie generowane po odrzuceniu pytania.
        /// </summary>
        public event EventHandler No;

        /// <summary>
        /// Konstruktor inicjalizujący okno dialogowe.
        /// </summary>
        public Dialog()
        {
            InitializeComponent();
            DataContext = this;
        }

        /// <summary>
        /// Pytanie wyświetlane w oknie dialogowym.
        /// </summary>
        public string Question { get; set; }

        /// <summary>
        /// Zamraża przyciski.
        /// </summary>
        /// <returns>Obiekt, na rzecz którego wywoływana jest metoda</returns>
        public Dialog Freeze()
        {
            yesButton.IsEnabled = false;
            noButton.IsEnabled = false;
            return this;
        }

        private void OnYesButtonClick(object sender, RoutedEventArgs e)
        {
            Freeze();
            if (Yes != null)
                Yes(this, new EventArgs());
        }

        private void OnNoButtonClick(object sender, RoutedEventArgs e)
        {
            Freeze();
            if (No != null)
                No(this, new EventArgs());
        }
    }
}
